package com.kc.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kc.bean.Lable;
import com.kc.bean.LableArticle;
import com.kc.mapper.LableMapper;
import com.kc.service.ILableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-10-22
 */
@Service
public class LableServiceImpl extends ServiceImpl<LableMapper, Lable> implements ILableService {

    @Resource
    private LableMapper lableMapper;

    @Override
    public int inster(Lable lable) {
        return lableMapper.insert(lable);
    }

    @Override
    public int getlableId(String lableName) {
        return lableMapper.getlableName(Wrappers.<Lable>lambdaQuery().eq(Lable::getLableName,lableName));
    }

    @Override
    public List<Lable> getLable(String[] lable) {
        List<Lable> lableList = new ArrayList<>();
        Lable lable1 = null;
        for (int i=0;i<lable.length;i++){
            lable1 = lableMapper.getlable(Wrappers.<Lable>lambdaQuery().eq(Lable::getLableName,lable[i]));
            if (lable1!=null){
                lableList.add(lable1);
            }
        }
        if (lableList.size()==0){
            return null;
        }
        return lableList;
    }

    @Override
    public List<Lable> getLableList(List<LableArticle> lableArticleList) {
        return lableMapper.getLable(Wrappers.<Lable>lambdaQuery().between(Lable::getLableId,
                lableArticleList.get(0).getLableId(),
                lableArticleList.get(lableArticleList.size()-1).getLableId()));
    }
}
